<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		Broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcastweb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;

class samdbo extends mysqli{

    public function __construct(){
		$conf = JooSamHelper::config();

		$conf->sql->port = (int) $conf->sql->port;
        parent::__construct($conf->sql->ip, $conf->sql->user, $conf->sql->pass, $conf->sql->db, $conf->sql->port);
        if (mysqli_connect_error()){
			$msg = JText::_('COM_JOOSAM_ERR_MYSQL').'(' . mysqli_connect_errno() . ') ' . mysqli_connect_error();
			JError::raiseError(500, $msg);
        }
    }

	public function NameQuote($string){
		
		$result = '`'.$string.'`';
		return $result;
	}

	public function Quote($string){
		
		$result = "'".addslashes($string)."'";

		return $result;
	}

	public function getObjectList($query){

		$data = false;
		
		if($result = $this->query($query)){
			while($row = $result->fetch_object()){
				$data[] = $row;
			}
			$result->close();
		}
		return $data;
	}

	public function countRows($query){
		
		$data = 0;
		if($result = $this->query($query)){
			$data = $result->num_rows;
			$result->close();
		}
		return $data;
	}

	public function sendQuery($query){

		$data = false;
		$this->query($query);
		$data = $this->affected_rows;
		$this->close();
		return $data;
	}
}